package com.example.Lezedata.ui.activity.goods;
import com.example.Lezedata.R;
import android.content.Context;
import android.util.AttributeSet;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.FrameLayout;
import android.widget.ImageView;

import androidx.annotation.Nullable;

import com.bumptech.glide.Glide;
import com.example.Lezedata.dataModel.BidDetailManager;
import com.example.Lezedata.dataModel.GoodsProjectModel;
import com.example.Lezedata.dataModel.ProgressModel;
import com.example.Lezedata.util.GBUtil;

import java.util.List;

import bid.Bid;


public class GoodsCell extends FrameLayout {

    private ImageView imageView;
    private GoodsNameView goodsNameView;
    private ProgressView progressView;
    private YellowButton button;
    private Context mContext;

    public Bid.BidItem model;

    public GoodsCell(Context context, @Nullable AttributeSet attrs) {
        super(context, attrs);
        LayoutInflater.from(context).inflate(R.layout.goods_cell,this);
        imageView = findViewById(R.id.goodsIcon);
        goodsNameView = findViewById(R.id.GoodsNameView);
        progressView = findViewById(R.id.ProgressView);
        button = findViewById(R.id.Buybutton);

        mContext = context;
    }

    public void setModel(final Bid.BidItem model1) {
        this.model = model1;
        BidDetailManager.getGoodsInfoForId(model1.getGoodsId(), new BidDetailManager.OnLoadDataComplete() {
            @Override
            public void infoResponse(Bid.GoodsInfo goodsInfo) {
                GBUtil.setGoodsImage(imageView,goodsInfo.getImgUrl());
                goodsNameView.setModel(GoodsNameViewModel.init(GBUtil.RoundToString(model.getBidRound()),goodsInfo.getName()));

                ProgressModel progressModel = new ProgressModel();
                progressModel.total = (int)model.getTotalBid();
                progressModel.current = (int)model.getTotalBid() - (int)model.getBidRemain();
                progressView.setModel(progressModel);

                String str = model.getBidPrice() + "NGN/Bid";
                button.setText(str);

            }
        });
    }
}
